<template>
  <div class="task-table">
    <el-table :data="tableList" border>
      <el-table-column label="序号" align="center" width="60">
        <template #default="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="任务状态" align="center" width="100">
        <template #default="scope">
          <div v-if="scope.row.taskStatus == 1">
            <el-button
              size="small"
              type="primary"
              @click="taskSureAction(scope.row)"
              >确认</el-button
            >
          </div>
          <div v-else>
            {{ selectDictLabel(task_status, scope.row.taskStatus) }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="任务单号" align="center" width="180">
        <template #default="scope">
          <el-button type="primary" link @click="pushTaskDetails(scope.row)">{{
            scope.row.codeNo
          }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="任务执行人" align="center" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.executorName) }}
        </template>
      </el-table-column>
      <el-table-column label="是否首检" align="center" width="90">
            <template #default="scope">
                <span v-if="scope.row.firstInspection === 1">已首检</span>
                <span v-else>未首检</span>
            </template>
        </el-table-column>

      <!-- <el-table-column label="工序号" align="center">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.processSerial) }}
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="工序编号" align="center" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.processFullCode) }}
        </template>
      </el-table-column> -->
      <el-table-column label="工序名称" align="center" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.processName) }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="工序任务状态" align="center" width="130">
        <template #default="scope">
          {{ selectDictLabel(task_status, scope.row.taskStatus) }}
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="产品编码" align="center" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.matterFullCode) }}
        </template>
      </el-table-column> -->
      <el-table-column label="产品名称" align="center" width="100">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.matterName) }}
        </template>
      </el-table-column>
      <el-table-column label="规格型号" align="center" width="100">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.matterSpecModel) }}
        </template>
      </el-table-column>
      <el-table-column label="单轨长度" align="center" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.monorailLength) }}
        </template>
      </el-table-column>
      <el-table-column label="本次任务数量" align="center" width="130">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.theTaskNum) }}
        </template>
      </el-table-column>
      <el-table-column label="基本单位" align="center" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.unitName) }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="辅助单位" align="center" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.assistUnitName) }}
        </template>
      </el-table-column> -->
      <el-table-column label="已汇报数量" align="center" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.reportNum) }}
        </template>
      </el-table-column>
      <el-table-column label="未汇报数量" align="center" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.unReportNum) }}
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.createTime) }}
        </template>
      </el-table-column>
      <el-table-column label="工艺要求" align="center" width="120">
        <template #default="scope">
          {{ blankAttributeDefault(scope.row.processContent) }}
        </template>
      </el-table-column>
        <el-table-column label="备注" align="center" width="120">
            <template #default="scope">
                {{ blankAttributeDefault(scope.row.remark) }}
            </template>
        </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { ref } from "vue";
import {
  pageReportExecuteProcessTaskApi,
  confirmReportProcessTaskApi,
} from "@/api/reportTask";
import { blankAttributeDefault } from "@/utils/index";
import { selectDictLabel } from "@/utils/ruoyi";
import { useRouter } from "vue-router";

const props = defineProps({
  taskStatus: {
    type: Number,
    default: -1,
  },
  planStartDate: {
    type: String,
    default: undefined,
  },
  planEndDate: {
    type: String,
    default: undefined,
  },
  createName: {
    type: String,
    default: undefined,
  },
  firstInspection: {
    type: String,
    default: undefined,
  },
});

const router = useRouter();
const { proxy } = getCurrentInstance();
const { task_status } = toRefs(proxy.useDict("task_status"));

const tableList = ref([]);
// 获取任务分页列表
const getList = async () => {
  // 参数
  let dic = {};
  if (props.taskStatus && props.taskStatus != -1) {
    dic["taskStatus"] = props.taskStatus;
  }
  if (props.planStartDate && props.planStartDate != null) {
    dic["planStartDate"] = props.planStartDate;
  }
  if (props.planEndDate && props.planEndDate != null) {
    dic["planEndDate"] = props.planEndDate;
  }
  if (props.createName && props.createName != null) {
    dic["createName"] = props.createName;
  }
  if (props.firstInspection && props.firstInspection != null) {
    dic["firstInspection"] = props.firstInspection;
  }
  const res = await pageReportExecuteProcessTaskApi(dic);
  tableList.value = res.data;
  console.log(res.data);
};
getList();

/** 确认 */
const taskSureAction = (row) => {
  ElMessageBox.confirm("是否确认?")
    .then(async () => {
      await confirmReportProcessTaskApi(row.id);
      getList();
    })
    .catch(() => {});
};

/** 跳转任务详情 */
const pushTaskDetails = (row) => {
  router.push({ path: "/task-edit", query: { id: row.id } });
};

watch(
  () => props.taskStatus,
  () => {
    console.log(props.taskStatus);
    getList();
  }
);

watch(
  () => props.planStartDate,
  () => {
    console.log(props.planStartDate);
    getList();
  }
);

watch(
  () => props.planEndDate,
  () => {
    getList();
  }
);

watch(
  () => props.firstInspection,
  () => {
    getList();
  }
);

watch(
  () => props.createName,
  () => {
    getList();
  }
);
</script>

<style lang="scss" scoped>
@include task-table;
.task-table {
  height: 100%;
  overflow-y: scroll;
}
</style>
